using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Health;
using Microsoft.Health.Web;
using System.Collections.ObjectModel;
using System.Globalization;


namespace DCHelper
{
    internal class Utilities
    {
        public static string XmlFromDateTime(DateTime dateTime)
        {
            return dateTime.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ", CultureInfo.InvariantCulture);
        }


        /// <summary>
        /// Get value from Health vault 
        /// </summary>
        /// <typeparam name="T">Generic type</typeparam>    
        /// <param name="typeID">TypeId for HealthRecordItem</param>
        /// <param name="accessor">Reference to HealthRecordAccessor</param>
        /// <returns>Object of generics</returns>
        public static T GetHealthRecordItemValue<T>(Guid typeID,
                                      HealthRecordAccessor accessor) where T : class
        {
            HealthRecordSearcher searcher = new HealthRecordSearcher(accessor);
            searcher.Filters.Add(new HealthRecordFilter(typeID));
            HealthRecordItemCollection items = searcher.GetMatchingItems()[0];
            if (items != null && items.Count > 0)
            {
                return items[0] as T;
            }
            else
            {
                return null;
            }
        }

    }
}
